import 'dart:io';

import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

class HttpSubscriptionService {
  static Future<Response> deleteCards(int tokenInd) {
    return BaseConfig.httpBase.deleteJson('/api/works/c/$tokenInd', null);
  }

  static Future<Response> setDefaultCard(int tokenInd) {
    return BaseConfig.httpBase.postJson('/api/works/c/$tokenInd/default', null);
  }

  /// 获取当前订阅的信息
  static Future<Response> getCompaniesSubscription() {
    return BaseConfig.httpBase.get('/api/companies/work', null);
  }

  /// 获取订阅数据
  static Future<Response> getSubscriptionsPlans({String type}) {
    return BaseConfig.httpBase.get('/api/works/p', {'type': type});
  }

  /// 获取支付方式
  static Future<Response> getSubscriptionsPaymentMethods() {
    return BaseConfig.httpBase.get('/api/works/pmw', null);
  }

  /// 获取信用卡number
  static Future<Response> getSubscriptionsCards() {
    return BaseConfig.httpBase.get('/api/works/c', null);
  }

  /// 获取 bill history
  static Future<Response> getSubBillHistory({int companyID}) {
    return BaseConfig.httpBase.get('/api/works', {'company_id': companyID});
  }

  /// 获取 sub company
  static Future<Response> getSubCompanies() {
    return BaseConfig.httpBase.get('/api/works/all', null);
  }

  /// 检查Promo code
  static Future<Response> checkCoupon(String code) {
    return BaseConfig.httpBase.postJson('/api/works/check_coupon', {
      'code': code,
    });
  }

  /// 获取当前订阅的信息
  static Future<Response> pay(
    int plan_id,
    String code,
    String token_id,
    int bill_to_company_id,
    String bill_phone_number,
    String bill_contact_name,
    String bill_postal_code,
    String bill_unit_number,
    String bill_address,
    String bill_company_name,
    String bill_country_code,
    String payment_method,
    int billId,
  ) {
    return BaseConfig.httpBase.postJson('/api/works/p', {
      "plan_id": plan_id,
      "code": code,
      'bill_id': billId,
      "token_id": token_id,
      "bill_to_company_id": bill_to_company_id,
      "bill_phone_number": bill_phone_number,
      "bill_contact_name": bill_contact_name,
      "bill_postal_code": bill_postal_code,
      "bill_unit_number": bill_unit_number,
      "bill_address": bill_address,
      "bill_company_name": bill_company_name,
      "bill_country_code": bill_country_code,
      "payment_method": payment_method,
      "is_ios": Platform.isIOS ? 1 : null
    });
  }

  //获取下一个订单
  static Future<Response> getNextBilling(int planId, int companyId) {
    return BaseConfig.httpBase.postJson('/api/works/next/p', {
      "plan_id": planId,
      "bill_to_company_id": companyId,
      'is_ios': Platform.isIOS ? "1" : "0",
    });
  }

  //获取下一个订单
  static Future<Response> cardsNew() {
    return BaseConfig.httpBase.postJson('/api/works/c/new', null);
  }

  //取消订阅
  static Future<Response> cancelSubscription() {
    return BaseConfig.httpBase.postJson('/api/works/cancel', null);
  }
}
